﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ModeSwitcher : MonoBehaviour
{
    private Button modeChangeBtn;

    private Text btnText;

    void Awake()
    {
        modeChangeBtn = transform.GetComponent<Button>();
        modeChangeBtn.onClick.AddListener(OnModeBtnClick);
        btnText = modeChangeBtn.transform.Find("Text").GetComponent<Text>();
                     
    }


    void Start()
    {
        InitModeText();
    }

    void OnModeBtnClick()
    {
        SwitchMode();
        
        ReFreashGame();
    }


    /// <summary>
    /// 重新加载场景
    /// </summary>
    void ReFreashGame()
    {
        string currentSceneName = PlayerPrefs.GetString("sceneName");
        MySceneManager.LoadScene(currentSceneName);
    }

    /// <summary>
    /// 切换模式按钮文字
    /// </summary>
    void SwitchMode()
    {
        if (btnText.text == "体验模式")
        {
            btnText.text = "教育模式";
            PlayerPrefs.SetString("mode", "教育模式");
        }
        else
        {          
            btnText.text = "体验模式";
            PlayerPrefs.SetString("mode", "体验模式");
        }
    }



    /// <summary>
    /// 初始化Mode按钮文本
    /// </summary>
    void InitModeText()
    {
        btnText.text = PlayerPrefs.GetString("mode");
    }


}
